using System;
using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.Instances;
using Caramel.Entities;

namespace Caramel.FluentNHibernate.Conventions
{
	public class NamedEntityUniqueNameConvention : IPropertyConvention
	{
		public void Apply(IPropertyInstance instance)
		{
			if (typeof(INamedEntity).IsAssignableFrom(instance.Property.DeclaringType) && (instance.Property.Name == "Name"))
			{
				instance.Unique();
			}
		}
	}
}
